package cn.liangjintang.webserver.zipfile;

import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStream;

public class MyOutputStream extends FilterOutputStream {

	public MyOutputStream(OutputStream out) {
		super(out);
	}

	final byte[] oneBytes = "1\r\n".getBytes();
	final byte[] rnBytes = "\r\n".getBytes();

	public void write(int b) throws IOException {
		out.write(oneBytes);
		out.write(b);
		out.write(rnBytes);
	}

	public void write(byte[] b) throws IOException {
		if (b.length < 1) {
		//	Flog.log("byte[] b is 0");
			return;
		}
		out.write(Integer.toHexString(b.length).getBytes());
		out.write(rnBytes);
		out.write(b);
		out.write(rnBytes);
	}

	public void write(byte[] b, int off, int len) throws IOException {
		if (len - off < 1) {
		//	Flog.log("byte[] , int off, int len is 0");
			return;
		}
		out.write(Integer.toHexString(len - off).getBytes());
		out.write(rnBytes);
		out.write(b, off, len);
		out.write(rnBytes);
	}

	/**
	 * 重写该方法,否则OutputStream会被关闭,其他的数据<br/>
	 * (如Transfer-Encoding: chunked传输结束标记)就不能再继续写入了
	 */
	public void close() throws IOException {
	}
}